<?php

/**
 * RabbitCMS
 */

/**
 * Show all module tasks in administrator's top menu
 */
class Core_View_Helper_SystemTask extends Zend_View_Helper_Abstract {

    /**
     * Get list of modules including its administrator tasks
     *
     * @return array
     */
    public function systemTask() {
        try {
            $request = Zend_Controller_Front::getInstance()->getRequest();
            $modules = array();
            $currentModule = $request->getModuleName();
            $currentController = $request->getControllerName();
            
            //core system user
            $item = array(
                'name' => $this->view->translate('menu_system_user', 'core'),
                'tasks' => array(),
                'current' => false
            );
            if($currentModule == 'core' && (
                    $currentController == 'role' || 
                    $currentController == 'user' || 
                    $currentController == 'privilege'
            ))
                $item['current'] = true;
            if ($this->view->routeAccessor('core_role_list'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_role', 'core'),
                    'link' => $this->view->url(array(), 'core_role_list')
                );
            if ($this->view->routeAccessor('core_user_list'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_user', 'core'),
                    'link' => $this->view->url(array(), 'core_user_list')
                );
            if ($this->view->routeAccessor('core_privilege_list'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_privilege', 'core'),
                    'link' => $this->view->url(array(), 'core_privilege_list')
                );
            $modules[] = $item;

            //core system config
            $item = array(
                'name' => $this->view->translate('menu_system_config', 'core'),
                'tasks' => array(),
                'current' => false
            );
            if($currentModule == 'core' && (
                    $currentController == 'language' 
                    || $currentController == 'locale'
                    || $currentController == 'config'
                    || $currentController == 'cache'
            )) $item['current'] = true;
            if ($this->view->routeAccessor('core_language_list'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_language', 'core'),
                    'link' => $this->view->url(array(), 'core_language_list')
                );
            if ($this->view->routeAccessor('core_locale_config'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_locale', 'core'),
                    'link' => $this->view->url(array(), 'core_locale_config')
                );
            if ($this->view->routeAccessor('core_config_app'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_config_app', 'core'),
                    'link' => $this->view->url(array(), 'core_config_app')
                );
            if ($this->view->routeAccessor('core_config_list'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_config', 'core'),
                    'link' => $this->view->url(array(), 'core_config_list')
                );
            if ($this->view->routeAccessor('core_cache_list'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_cache', 'core'),
                    'link' => $this->view->url(array(), 'core_cache_list')
                );
            if ($this->view->routeAccessor('core_cache_config'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_cache_config', 'core'),
                    'link' => $this->view->url(array(), 'core_cache_config')
                );
            $modules[] = $item;

            //core custome
            $item = array(
                'name' => $this->view->translate('menu_custome', 'core'),
                'tasks' => array(),
                'current' => false
            );
            if($currentModule == 'core' && (
                    $currentController == 'template' 
                    || $currentController == 'permalink'
            )) $item['current'] = true;
            
            if ($this->view->routeAccessor('core_template_list'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_template', 'core'),
                    'link' => $this->view->url(array(), 'core_template_list')
                );
            if ($this->view->routeAccessor('core_permalink_index'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_permalink', 'core'),
                    'link' => $this->view->url(array(), 'core_permalink_index')
                );
            $modules[] = $item;

            //core extend
            $item = array(
                'name' => $this->view->translate('menu_extend', 'core'),
                'tasks' => array(),
                'current' => false
            );
            if($currentModule == 'core' && (
                    $currentController == 'module' 
                    || $currentController == 'plugin'
                    || $currentController == 'widget'
                    || $currentController == 'hook'
                    || $currentController == 'target'
            )) $item['current'] = true;
            
            if ($this->view->routeAccessor('core_module_list'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_module', 'core'),
                    'link' => $this->view->url(array(), 'core_module_list')
                );
            if ($this->view->routeAccessor('core_plugin_list'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_plugin', 'core'),
                    'link' => $this->view->url(array(), 'core_plugin_list')
                );
            if ($this->view->routeAccessor('core_widget_list'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_widget', 'core'),
                    'link' => $this->view->url(array(), 'core_widget_list')
                );
            if ($this->view->routeAccessor('core_hook_list'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_hook', 'core'),
                    'link' => $this->view->url(array(), 'core_hook_list')
                );
            if ($this->view->routeAccessor('core_target_list'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_target', 'core'),
                    'link' => $this->view->url(array(), 'core_target_list')
                );
            $modules[] = $item;

            //core report
             $item = array(
                'name' => $this->view->translate('menu_report', 'core'),
                'tasks' => array(),
                 'current' => false
            );
             if($currentModule == 'core' && (
                    $currentController == 'log' 
            )) $item['current'] = true;
            if ($this->view->routeAccessor('core_log_list'))
                $item['tasks'][] = array(
                    'label' => $this->view->translate('menu_log', 'core'),
                    'link' => $this->view->url(array(), 'core_log_list')
                );
            $modules[] = $item;
            return $modules;
        } catch (Exception $ex) {
            echo $ex->getMessage();
            return null;
        }
    }

}
